package com.tianchi.lexiang.background;

import com.tianchi.lexiang.R;
import com.tianchi.lexiang.background.util.PublicUtil;
import com.tianchi.lexiang.bean.LeXiangConstants;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class SingerAdd extends Activity implements OnItemClickListener {
	
	public static final String SINGER_ADD = "SingerAdd";
	
	private ListView backgroundSettingList;
	private Button backBtn;
	
	private PublicUtil publicUtil ;
	private LanAddSongIPSetting lasips;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.background_setting);
		initView();
		publicUtil = PublicUtil.getPulibUtil();
		lasips = LanAddSongIPSetting.getInstance();
	}
	
	private void initView() {
		backgroundSettingList = (ListView) findViewById(R.id.background_setting_list);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, this.getResources().getStringArray(R.array.singer_add));
		backgroundSettingList.setAdapter(adapter);
		backgroundSettingList.setOnItemClickListener(this);
		backBtn = (Button) findViewById(R.id.back_btn);
		backBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				SingerAdd.this.finish();
			}
		});
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		
		Intent intent = new Intent();
		switch (position) {
		case 0:
			if (publicUtil.detectionuDisk(LeXiangConstants.SINGER_UDISK_PATH)) {
				intent.setClass(SingerAdd.this, UdiskAddSingers.class);
				SingerAdd.this.startActivity(intent);
			} else {
				dialog(getString(R.string.udisk_add_singer_tip));
			}
			break;
		case 1:
			lasips.openDialog(SingerAdd.this, SINGER_ADD);
			break;

		default:
			break;
		}
	}

	private void dialog(String tip) {
		AlertDialog.Builder builder = new Builder(SingerAdd.this);
			builder.setMessage(tip);
			builder.setIcon(android.R.drawable.ic_menu_info_details);
			builder.setTitle(getString(R.string.tip));
			builder.setPositiveButton(R.string.confirm, new Dialog.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});
			builder.create().show();
			}

}
